def run(params:list[str]):
    import pandas as pd
    from mlxtend.preprocessing import TransactionEncoder
    from mlxtend.frequent_patterns import apriori, fpgrowth

    from ApiBase import apiBase
    import json
    try:
        data=apiBase.argv_json(params,1,{"2":"牛奶,豆奶","4":"面包,牛奶"})
        threshold=apiBase.argv(params,2,0.6)
        # apiBase.log("param1="+str(data))    
        # apiBase.log("param2="+str(threshold))
        # #dataset=[['牛奶', '豆奶'],  ['面包',  '牛奶']]
        dataset=[]
        for value in data.values():
            #print(value)        
            ls=value.split(",")
            dataset.append(ls)    
        #dataset=[['牛奶', '豆奶'],  ['面包',  '牛奶']]
        
        # 示例数据集（一个列表的列表，其中每个内部列表表示一个事务）
        # dataset = [['牛奶', '洋葱', '营养麦片', '豆奶'],
        # ['面包', '黄油', '牛奶'],
        # ['黄油', '营养麦片', '豆奶'],
        # ['牛奶', '洋葱', '面包', '黄油'],
        # ['面包', '黄油', '豆奶'],
        # ['面包', '牛奶', '黄油', '营养麦片'],
        # ['牛奶', '洋葱', '面包', '黄油', '豆奶']]
        # 将数据集转换为适合FP-Growth算法的格式
        te = TransactionEncoder()
        te_ary = te.fit(dataset).transform(dataset)
        df = pd.DataFrame(te_ary, columns=te.columns_)
        # 使用FP-Growth算法寻找频繁项集
        frequent_itemsets = apriori(df, min_support=0.2, use_colnames=True)
        # 打印频繁项集
        #print(frequent_itemsets)

        # 如果你想进一步得到频繁项集的关联规则，可以使用mlxtend的association_rules函数
        from mlxtend.frequent_patterns import association_rules
        rules = association_rules(frequent_itemsets, metric="confidence", min_threshold=threshold)
        #print(rules)
        data={}
        data['rel']=[]
        for i, j  in rules.iterrows():
            X = j['antecedents']
            Y = j['consequents']
            #conf = str(j['confidence'])
            x = ', '.join([item for item in X])
            y = ', '.join([item for item in Y])
            item={}
            item['antecedents'] = x
            item['consequents'] = y
            item['confidence'] = j['confidence']
            data['rel'].append(item)
            
        return json.dumps(data,ensure_ascii=False)
    except Exception as e:
        return f"function error:{e}"


